<?php
namespace Home\Controller;
use Think\Controller;
use Think\Pinyin;
use Home\Aip\Store;
 
class SpGoodsController extends CommonController {
	protected $st_store = 'store';//店铺表
	protected $tb_goods = 'product';//产品数据表
	protected $st_class = 'store_class';//店铺分类表
	protected $gc_class = 'goods_class';//商品分类表
	protected $area = 'area';//地址分类表
	
	
	/*
	*商品详情
	*
	*/		
	public function index_goods() {
		
		unset($cache);	
		$cache = 'goods'.$_GET['gid'] ;
		S($cache,null) ;

		if (S($cache)) {
			$goods = S($cache) ;
		} else {
			$goods = $this->goods_info_a($_GET['gid']) ;
			//所属店铺
			$store = $this->g_store_info($goods['st_id']) ;
			if ($store ['store_label']) {
				$store ['label_s'] = 1 ;
			}
			
			if ($store ['store_qq']) {
				$store ['qq'] = 1 ;
			}
			
			//图片集（规格）
			$goods['imgset'] = strAnalysis($goods['imgset']) ;
			$goods['imgset'] =	$goods['imgset'] ;
			
			//颜色
			$goods_color = strAnalysis($goods['goods_color']) ;
			
			//规格
		    $goods_spec = strAnalysis($goods['goods_spec']) ;	
				
			if(!$goods_spec){
				$goods_spec = unserialize($goods['goods_spec'] );
			}
			if(!$goods_color){
				$goods_color = unserialize($goods['goods_color'] );
			}
			$goods['goods_spec_arr'] = unserialize($goods["goods_spec_arr"]);
			
			$goods['goods_color'] = $goods_color ;
			$goods['goods_spec'] = $goods_spec ;
			
			$goods_color && $goods['goods_c'] = 1 ;
			$goods_spec && $goods['goods_s'] = 2 ;
					
			$goods['content'] = html_entity_decode($goods['content']) ;	
			
			$goods['store'] = $store ;
			
			
			//保存缓存
			S($cache,$goods) ;			
		}
		
		$goods['price'] = number_format($goods['price'],2) ;
		$shop_area_ids = unserialize($goods ['shop_area_ids']) ;
		//支付方式
		$result = shop_pay_type($shop_area_ids,$goods);
		$pay_name = $result['pay_name'] ;
		$m_html = $result['m_html'] ;	

		//支付方式
		$pay_html = '<dl class="good-price"><dt>'.$pay_name.'：</dt><dd class="price"><strong>'.$m_html.'</strong></dd></dl>';
			
		//最新产品
		unset($cache) ;
		$cache = 'g_new'.$goods['st_id'] ;
		$st_g_new = $this->goods_info_search($goods['st_id'],1,'id',$cache,$peg=1,$num=6) ;
		
		//热销产品 热销商品排行
		unset($cache) ;
		$cache = 'host_sell'.$goods['st_id'] ;
		$host_sell = $this->goods_info_search($goods['st_id'],1,'goods_salenum',$cache,$peg=1,$num=6) ;
		
		//人气产品 热门收藏排行
		unset($cache) ;
		$cache = 'host_collect'.$goods['st_id'] ;
		$host_collect = $this->goods_info_search($goods['st_id'],1,'goods_collect',$cache,$peg=1,$num=6) ;
		
		//推荐商品
		unset($cache) ;
		$cache = 'g_recom'.$goods['st_id'] ;
		$st_g_recom = $this->goods_info_search($goods['st_id'],1,'goods_commend',$cache,$peg=1,$num=5) ;
		
		//dump($goods);die;
		//dump($host_sell);die;
		$this->assign('host_sell',$host_sell);	//热销商品排行
		$this->assign('host_collect',$host_collect);	//热门收藏排行
		$this->assign('st_g_recom',$st_g_recom);	//推荐商品
		$this->assign('st_g_new',$st_g_new);	//最新产品
		$this->assign('goods',$goods) ;
		$this->assign('pay_html',$pay_html) ;//支付方式
		$this->assign('pay_name',$pay_name) ;
		$this->assign('m_html',$m_html) ;
		$this->assign('unit',$result['unit']) ;//支付单位
		//获取商品规格
		if(I('post.goods_spec_all')==="runing"){
			
			if(true===I('post.type')){
				//
			} else {
				$this->ajaxReturn($goods['goods_spec_arr']);
			}
			
		}
		
		$this->display();		
	}
	
	/*
	*商品信息和所有商品
	*
	*/		
	private function goods_info_a($gid) {
		
		$goods = array();
		//联查
		unset($str);
		unset($data);		
		$str = "id=%d";
		$data = array($gid) ;			
		$gd_list = _getOne($this->tb_goods,$str,$data) ;
		
		//商品分类
		$gc_1 = _getOne($this->gc_class,'gc_id=%d',array($gd_list['gc_id'])) ;
		$gd_list['gc_id_1'] && $gc_2 = _getOne($this->gc_class,'gc_id=%d',array($gd_list['gc_id_1'])) ;
		$gd_list['gc_id_2'] && $gc_3 = _getOne($this->gc_class,'gc_id=%d',array($gd_list['gc_id_2'])) ;
		$gc_list = array() ;
		$gc_list[0]['name'] = $gc_1['gc_name'] ;
		$gc_list[0]['id'] = $gc_1['gc_id'] ;
		$gc_2['gc_name'] && $gc_list[1]['name'] = $gc_2['gc_name'] ;
		$gc_2['gc_name'] && $gc_list[1]['id'] = $gc_2['gc_id'] ;		
		$gc_3['gc_name'] && $gc_list[2]['name'] = $gc_3['gc_name'] ;
		$gc_3['gc_name'] && $gc_list[2]['id'] = $gc_3['gc_id'] ;

		$gd_list ['grade_list'] = $gc_list ;
		
		if (!$_SESSION['admin_id']) {
			if ($gd_list['goods_verify']!='1' || $gd_list['goods_state']!='1') {
				//dump($_SESSION['admin_id']);die;
				$this->error('商品已下架','index');
			}			
		}
		
		$goods = $gd_list ;		
		return $goods ;	
	}
	
	/*
	*商品按条件检索
	*
	*/		
	private function goods_info_search($stid,$type=0,$word='id',$cache,$peg=1,$num=6) {
				
		if ($type) {
			
			S($cache,null) ;
			
			if (S($cache)) {
				$goods_list = S($cache) ;
			}
			
			unset($str);
			unset($data);
			unset($field);		
			$str = "st_id=%d and goods_state=%d and goods_verify=%d";
			$data = array($stid,1,1) ;				
			$field = 'productname,id,pic,price,goods_storage,goods_collect,goods_salenum,goods_commend,imgset,goods_color,goods_spec,point_num,coin_num' ;	
			$order = $word.' desc';	
			
			//所有商品		
			!$goods_list && $goods_list = _getList($this->tb_goods,$str,$data,$cache,$order,$peg,$num,$field) ;
			
			foreach ($goods_list as $key=>$v) {
				$goods_list [$key]['imgset'] = strAnalysis($v['imgset']) ;
				$goods_list [$key]['price'] = number_format($v['price'],2) ;
				//颜色
				$goods_list [$key]['goods_color'] = strAnalysis($v['goods_color']) ;
				//规格
				$goods_list [$key]['goods_spec'] = strAnalysis($v['goods_spec']) ;
			}
			
			//$store['goods_list'] = $goods_list ;			
		}
		
		return $goods_list ;	
	}
	
	/*
	*所属店铺信息
	*
	*/		
	private function g_store_info($stid) {
		
		unset($str);
		unset($data);
		unset($field);
		$str = "store_id=%d and store_state=%d";
		$data = array($stid,1) ;
		$field = 'store_name,seller_name,is_own_shop,store_presales,store_aftersales,store_workingtime,store_label,store_qq,store_ww,store_phone,store_state,store_collect' ;	
		$st_list = _getOne($this->st_store,$str,$data,'',$field) ;

		if (!$st_list && !$_SESSION['admin_id']) {
			$this->error('商品已下架','index');
		}
		
		$store = $st_list ;
		//dump($store);die;	
		return $store ;	
	}
	
	
	/*
	* 分类商品
	*/	
	public function fenlei_goods(){	

        if(I('get.keyword') && I('get.search_act')=='goods_search'){
        	$map['productname'] = array('LIKE','%'.I('get.keyword').'%');
        } else {

			$str=$_SERVER["REQUEST_URI"];
			$c='&p=';
			if(strpos($str, $c) !== false){
				$r1  =  strstr ( $str ,  $c ,  true );  // 截取字符串
			}else{
				$r1  =  $str;
			}
			$this->r1=$r1;
			
			$dp['store_state']=1;//店铺开启

			$dpid = M($this->st_store)->field("store_id")->where($dp)->select();

			$ff=array();
			for($i=0;$i<count($dpid);$i++)
			{
				$ff[]= array('like',$dpid[$i]['store_id']);
			}
			$a=count($ff);
			if($a>=1){
				$ff[$a]='ThinkPHP';
				$ff[$a+1]='or';

				$map['st_id']=$ff;
			}else{
				$map['st_id']='';
			}

			$where['gc_name']=I('get.gc_name');

			$gc = M($this->gc_class)->where($where)->find();

			$map['gc_id|gc_id_1|gc_id_2'] = $gc['gc_id'];

			$priceMin=I('get.priceMin');
			$priceMax=I('get.priceMax');
			$this->priceMin=$priceMin;
			$this->priceMax=$priceMax;
			
			if ($priceMin <> '' && $priceMax <> '') {
				$map['price'] = array(array('egt',$priceMin),array('elt',$priceMax));
			}elseif ($priceMin <> '' && $priceMax == '') {
				$map['price'] = array('egt',$priceMin);
			}elseif ($priceMin == '' && $priceMax <> '') {
				$map['price'] = array('elt',$priceMax);
			}

			$pt=I('get.pt');
			$this->pt=$pt;
			if($pt==1){
				$map['is_own_shop'] = $pt;
			}

			$zp=I('get.zp');
			$this->zp=$zp;
			if($zp==1){
				$map['price'] = 0;
			}

			$provid=I('get.provid');
			$this->provid=$provid;
			$diqu=M($this->area)->where(array('area_id'=>$provid))->find();
			$this->area_name=$diqu['area_name'];
			if(I('get.provid')){
				$map['province_id'] = $provid;
			}
		
		}
		
		$map['goods_state'] = 1;//商品状态 正常
		$map['goods_verify'] = 1;//商品审核 通过
		$num=8;

		$count = M($this->tb_goods)->where($map)->count();// 查询满足要求的总记录数
		$ye_num=$count/$num;
		// echo $ye_num."<br>";
		$ye_num=ceil($ye_num); //有余数则进1
		// echo $ye_num;

		$ps=I('get.p');
		if($ps<=1 && $ye_num>1){
			$next=2;
		}elseif($ps>1 && $ps<$ye_num){
			$prev=$ps-1;
			$next=$ps+1;
		}elseif($ps>=$ye_num){
			$prev=$ps-1;
		}
		$this->prev=$prev;
		$this->next=$next;
		
		$p = getpage($count, $num);

		$paixu=I('get.paixu');
		$this->paixu=$paixu;
		$order='id ASC';
		if($paixu=='mr'){
			$order='id ASC';
		}elseif($paixu=='xl'){
            $order='goods_salenum DESC';
		}elseif($paixu=='rq'){
			$order='goods_collect DESC';
		}elseif($paixu=='jg'){
			$order='price DESC';
		}

		$list = M($this->tb_goods)->where($map)->order($order)->limit($p->firstRow, $p->listRows)->select();
		for($i=0;$i<count($list);$i++){
			$dpmc=M($this->st_store)->where(array('store_id'=>$list[$i]['st_id']))->find();
			$list[$i]['dpmc']=$dpmc['store_name'];
			$list[$i]['imgset'] = strAnalysis($list[$i]['imgset']) ;
			//支付方式
			unset($result);
			$list[$i]['shop_area_ids'] = unserialize($list[$i]['shop_area_ids']);
			$result = shop_pay_type($list[$i]['shop_area_ids'],$list[$i]);
			
			$list[$i]['pay_name'] = $result['pay_name'] ;
			$list[$i]['m_html'] = $result['m_html'] ;
			
		}
		//dump($list);die;
		$this->assign('gc',$gc);
		$this->assign('list',$list);
		$this->assign('page',$p->show());

		$map['goods_commend'] = 1;

		$tuijsp = M($this->tb_goods)->where($map)->limit(4)->select();
		
		$this->assign('tuijsp',$tuijsp);

		$title=array();

		while($gc<>''){
			$gc_sj = M($this->gc_class)->where(array('gc_id'=>$gc['gc_parent_id']))->find();
			if($gc_sj){
				$title[]=$gc_sj['gc_name'];
				$gc = $gc_sj;
			}else{
				break;
			}
		}
		// dump($title);
		krsort($title);//数组倒序
		// dump($title);
		$tnum=count($title)-1;
		$gc_name=$title[$tnum];
		if($tnum<0){
			$gc_name=I('get.gc_name');
		}
		// die;
		$this->assign('title',$title);

		$tree = M($this->gc_class)->field("gc_id,gc_name")->where(array('gc_parent_id'=>0,'gc_name'=>$gc_name))->select();
		$xxj=M($this->gc_class)->field("gc_parent_id")->where(array('gc_name'=>I('get.gc_name')))->find();
		for($i=0;$i<count($tree);$i++){

			$gc_xj = M($this->gc_class)->field("gc_id,gc_name")->where(array('gc_parent_id'=>$tree[$i]['gc_id']))->select();
			
			for($j=0;$j<count($gc_xj);$j++){

				if($gc_xj[$j]['gc_name']==I('get.gc_name') || $gc_xj[$j]['gc_id']==$xxj['gc_parent_id']){
					if($j>0){
						$gc_xj0=$gc_xj[0];
						$gc_xj[0]=$gc_xj[$j];
						$gc_xj[$j]=$gc_xj0;
					}
				}
			}
			for($j=0;$j<count($gc_xj);$j++){

				$gc_xxj = M($this->gc_class)->field("gc_id,gc_name")->where(array('gc_parent_id'=>$gc_xj[$j]['gc_id']))->select();
			    $gc_xj[$j]['gc_xxj']=$gc_xxj;
			}
			$tree[$i]['gc_xj']=$gc_xj;
		}
		// dump($tree);

		$this->assign('tree',$tree);
		$this->display();
	}

	
	/*
	*商品现金区
	*
	*/		
	public function money_goods(){
		
		if (!$_GET['p']) {
			$_GET['p'] = 1;
		}		
		unset($order);
		unset($str);
		unset($data);
		unset($field);
		unset($join);
		$num = 16 ;
		$order = 'id desc';

		$str['id'] = array('GT',0);
		$str['st.store_state'] = array('EQ',1);
		$str['goods_state'] = array('EQ',1);
		$str['goods_verify'] = array('EQ',1);
		$str['goods_commend'] = array('EQ',1);
		$str['tm_product.shop_area_ids'] = array('LIKE','%\"1\"%');

		$join = ' LEFT JOIN __STORE__ AS st ON st_id=st.store_id ' ;
		$field = 'productname,id,pic,price,st_id,goods_marketprice,goods_discount,st.store_name,tm_product.shop_area_ids,minpic' ;
		//分页
		$show = Page($this->tb_goods,$str,$data,$num,$join);		

		//查询
		$goods_list = _getJoinList($this->tb_goods,$join,$str,$data,'',$order,$_GET['p'],$num,$field);

		foreach ($goods_list as $key=>$v) {
			unset($minpic);		
			if (!$v['minpic']) {								
				$minpic = thumb_img($v['pic'], $name = 'goods', $type=2 , $v, 300,300) ;
			}
			if ($minpic) {
				$goods_list [$key]['pic'] = $minpic ;
				unset($data);
				$data['minpic'] = $minpic ;
				$deit =  M('product')->where(array('id'=>$v['id']))->save($data);
			} else {
				if (!$v['minpic']) {
					$v['goods'] [$kk]['minpic'] = $v['pic'] ;
				}
			}
			//dump($goods_list);die;
			$goods_list[$key]['j_price'] = $v['goods_marketprice'] - $v['price'] ;
			$goods_list[$key]['pay_name'] = "商城价&nbsp;";
			$goods_list[$key]['m_html'] = '¥'.$v['price'].'';
		}
		
		//商品分类		
		unset($cache);
		unset($order);
		unset($str);
		unset($data);
		//S('gc_class_list',null);
		$cache = 'gc_class_list';
		$order = 'gc_id desc';				
		$str = "gc_name<>'%s' and gc_parent_id=%d";
		$data = array('',0) ;		
		$gc_list = _getList($this->gc_class,$str,$data,$cache,$order) ;		
		
		$this->assign('title', '现金区');
		$this->assign('gc_list',$gc_list);		
		$this->assign('page',$show);
		$this->assign('goods_list',$goods_list);
		$this->display();
	}

	/*
	*商品积分区
	*
	*/		
	public function integration_goods(){
		if (!$_GET['p']) {
			$_GET['p'] = 1;
		}		
		unset($order);
		unset($str);
		unset($data);
		unset($field);
		unset($join);
		$num = 16 ;
		$order = 'id desc';

		$str['id'] = array('GT',0);
		$str['st.store_state'] = array('EQ',1);
		$str['goods_state'] = array('EQ',1);
		$str['goods_verify'] = array('EQ',1);
		$str['goods_commend'] = array('EQ',1);
		$str['tm_product.shop_area_ids'] = array('LIKE','%\"2\"%');

		$join = ' LEFT JOIN __STORE__ AS st ON st_id=st.store_id ' ;
		$field = 'productname,id,pic,price,st_id,goods_marketprice,goods_discount,st.store_name,tm_product.shop_area_ids,tm_product.point_num,minpic' ;
		//分页
		$show = Page($this->tb_goods,$str,$data,$num,$join);		

		//查询
		$goods_list = _getJoinList($this->tb_goods,$join,$str,$data,'',$order,$_GET['p'],$num,$field);

		foreach ($goods_list as $key=>$v) {
			unset($minpic);		
			if (!$v['minpic']) {								
				$minpic = thumb_img($v['pic'], $name = 'goods', $type=2 , $v, 300,300) ;
			}
			if ($minpic) {
				$goods_list [$key]['pic'] = $minpic ;
				unset($data);
				$data['minpic'] = $minpic ;
				$deit =  M('product')->where(array('id'=>$v['id']))->save($data);
			} else {
				if (!$v['minpic']) {
					$v['goods'] [$kk]['minpic'] = $v['pic'] ;
				}
			}
			$goods_list[$key]['j_price'] = $v['goods_marketprice'] - $v['price'] ;

			$goods_list[$key]['pay_name'] = "积分价&nbsp;";
			$goods_list[$key]['m_html'] = '<font style="">'.$v['point_num'].'</font>&nbsp;<font style="font-size:15px;">积分</font>';
				
		}
	
		//商品分类		
		unset($cache);
		unset($order);
		unset($str);
		unset($data);
		//S('gc_class_list',null);
		$cache = 'gc_class_list';
		$order = 'gc_id desc';				
		$str = "gc_name<>'%s' and gc_parent_id=%d";
		$data = array('',0) ;		
		$gc_list = _getList($this->gc_class,$str,$data,$cache,$order) ;			
		//dump($goods_list);die;
		$this->assign('title', '积分区');
		$this->assign('gc_list',$gc_list);		
		$this->assign('page',$show);
		$this->assign('goods_list',$goods_list);
		$this->display('money_goods');
	}

	/*
	*商品积分+现金区
	*
	*/		
	public function integration_money_goods(){
		
		if (!$_GET['p']) {
			$_GET['p'] = 1;
		}		
		unset($order);
		unset($str);
		unset($data);
		unset($field);
		unset($join);
		$num = 16 ;
		$order = 'id desc';

		$str['id'] = array('GT',0);
		$str['st.store_state'] = array('EQ',1);
		$str['goods_state'] = array('EQ',1);
		$str['goods_verify'] = array('EQ',1);
		$str['goods_commend'] = array('EQ',1);
		$str['tm_product.shop_area_ids'] = array('LIKE','%\"3\"%');

		$join = ' LEFT JOIN __STORE__ AS st ON st_id=st.store_id ' ;
		$field = 'productname,id,pic,price,st_id,goods_marketprice,goods_discount,st.store_name,tm_product.shop_area_ids,tm_product.point_num,minpic' ;
		//分页
		$show = Page($this->tb_goods,$str,$data,$num,$join);		

		//查询
		$goods_list = _getJoinList($this->tb_goods,$join,$str,$data,'',$order,$_GET['p'],$num,$field);

		foreach ($goods_list as $key=>$v) {
			unset($minpic);		
			if (!$v['minpic']) {								
				$minpic = thumb_img($v['pic'], $name = 'goods', $type=2 , $v, 300,300) ;
			}
			if ($minpic) {
				$goods_list [$key]['pic'] = $minpic ;
				unset($data);
				$data['minpic'] = $minpic ;
				$deit =  M('product')->where(array('id'=>$v['id']))->save($data);
			} else {
				if (!$v['minpic']) {
					$v['goods'] [$kk]['minpic'] = $v['pic'] ;
				}
			}
			$goods_list[$key]['j_price'] = $v['goods_marketprice'] - $v['price'] ;
			$goods_list[$key]['pay_name'] = "现金+积分";
			$goods_list[$key]['m_html'] = '¥'.$v['price'].'&nbsp;+&nbsp;<font style="font-size:19px;">'.$v['point_num'].'</font><font style="font-size:12px;">&nbsp;积分</font>';
		}
		//dump($goods_list);die;
		//商品分类		
		unset($cache);
		unset($order);
		unset($str);
		unset($data);
		//S('gc_class_list',null);
		$cache = 'gc_class_list';
		$order = 'gc_id desc';				
		$str = "gc_name<>'%s' and gc_parent_id=%d";
		$data = array('',0) ;		
		$gc_list = _getList($this->gc_class,$str,$data,$cache,$order) ;		
		
		//dump($goods_list);die;
		$this->assign('title', '积分+现金区');
		$this->assign('gc_list',$gc_list);		
		$this->assign('page',$show);
		$this->assign('goods_list',$goods_list);
		$this->display('money_goods');
	}

	/*
	*商品抢购区
	*
	*/	
	public function purchase_goods(){
		
		if (!$_GET['p']) {
			$_GET['p'] = 1;
		}		
		unset($order);
		unset($str);
		unset($data);
		unset($field);
		unset($join);
		$num = 16 ;
		$order = 'id desc';

		$str['id'] = array('GT',0);
		$str['st.store_state'] = array('EQ',1);
		$str['goods_state'] = array('EQ',1);
		$str['goods_verify'] = array('EQ',1);
		$str['goods_commend'] = array('EQ',1);
		$str['tm_product.shop_area_ids'] = array('LIKE','%\"4\"%');

		$join = ' LEFT JOIN __STORE__ AS st ON st_id=st.store_id ' ;
		$field = 'productname,id,pic,price,st_id,goods_marketprice,goods_discount,st.store_name,minpic' ;
		//分页
		$show = Page($this->tb_goods,$str,$data,$num,$join);		

		//查询
		$goods_list = _getJoinList($this->tb_goods,$join,$str,$data,'',$order,$_GET['p'],$num,$field);

		foreach ($goods_list as $key=>$v) {
			unset($minpic);		
			if (!$v['minpic']) {
								
				$minpic = thumb_img($v['pic'], $name = 'goods', $type=2 , $v, 300,300) ;
			}
			if ($minpic) {
				$goods_list [$key]['pic'] = $minpic ;
				unset($data);
				$data['minpic'] = $minpic ;
				$deit =  M('product')->where(array('id'=>$v['id']))->save($data);				
			} else {
				if (!$v['minpic']) {
					$v['goods'] [$kk]['minpic'] = $v['pic'] ;
				}
			}
			$goods_list[$key]['j_price'] = $v['goods_marketprice'] - $v['price'] ;
		}
	
		//商品分类		
		unset($cache);
		unset($order);
		unset($str);
		unset($data);
		//S('gc_class_list',null);
		$cache = 'gc_class_list';
		$order = 'gc_id desc';				
		$str = "gc_name<>'%s' and gc_parent_id=%d";
		$data = array('',0) ;		
		$gc_list = _getList($this->gc_class,$str,$data,$cache,$order) ;		
		
		//dump($goods_list);die;
		$this->assign('title', '抢购区');
		$this->assign('gc_list',$gc_list);		
		$this->assign('page',$show);
		$this->assign('goods_list',$goods_list);
		$this->display('money_goods');
	}
	
	/*
	*增值区
	*
	*/		
	public function sp_coin_goods(){
		if (!$_GET['p']) {
			$_GET['p'] = 1;
		}		
		unset($order);
		unset($str);
		unset($data);
		unset($field);
		unset($join);
		$num = 16 ;
		$order = 'id desc';

		$str['id'] = array('GT',0);
		$str['st.store_state'] = array('EQ',1);
		$str['goods_state'] = array('EQ',1);
		$str['goods_verify'] = array('EQ',1);
		$str['goods_commend'] = array('EQ',1);
		$str['tm_product.shop_area_ids'] = array('LIKE','%\"5\"%');

		$join = ' LEFT JOIN __STORE__ AS st ON st_id=st.store_id ' ;
		$field = 'productname,id,pic,price,st_id,goods_marketprice,goods_discount,st.store_name,tm_product.shop_area_ids,tm_product.point_num,tm_product.coin_num,minpic' ;
		//分页
		$show = Page($this->tb_goods,$str,$data,$num,$join);		

		//查询
		$goods_list = _getJoinList($this->tb_goods,$join,$str,$data,'',$order,$_GET['p'],$num,$field);
		
		foreach ($goods_list as $key=>$v) {
			unset($minpic);		
			if (!$v['minpic']) {								
				$minpic = thumb_img($v['pic'], $name = 'goods', $type=2 , $v, 300,300) ;
			}
			//dump($minpic);die;
			if ($minpic) {
				$goods_list [$key]['pic'] = $minpic ;
				unset($data);
				$data['minpic'] = $minpic ;
				$deit =  M('product')->where(array('id'=>$v['id']))->save($data);
			} else {
				if (!$v['minpic']) {
					$v['goods'] [$kk]['minpic'] = $v['pic'] ;
				}
			}
			 
			$goods_list[$key]['j_price'] = $v['goods_marketprice'] - $v['price'] ;

			$goods_list[$key]['pay_name'] = "增值币价&nbsp;";
			$goods_list[$key]['m_html'] = '<font style="">'.$v['coin_num'].'</font>&nbsp;<font style="font-size:15px;">币</font>';
				
		}
		
	
		//商品分类		
		unset($cache);
		unset($order);
		unset($str);
		unset($data);
		//S('gc_class_list',null);
		$cache = 'gc_class_list';
		$order = 'gc_id desc';				
		$str = "gc_name<>'%s' and gc_parent_id=%d";
		$data = array('',0) ;		
		$gc_list = _getList($this->gc_class,$str,$data,$cache,$order) ;			
		
		$this->assign('title', '增值区');
		$this->assign('gc_list',$gc_list);		
		$this->assign('page',$show);
		$this->assign('goods_list',$goods_list);
		$this->display('money_goods');
	}
	
	/**
	*不能购买自己店铺的产品
	*/	
	public function buy_chack() {
		if (IS_POST && I('post.atc')==='buy_chack') {
			$str = 'member_id=%d and store_id=%d' ;
			$arr = array($_SESSION['user_id'], I('post.st_id')) ;
			$field = "member_id,store_id,store_name" ;
			$buy_store = _getOne('store', $str, $arr, '', $field) ;
					
			if ($buy_store) {
				$result = array('msg'=>'不能购买自己店铺的产品') ;
				$this->ajaxReturn($result);					
			} else {
				$this->ajaxReturn(1);
			}						
		}
	}
	
}